<% add_decidim_page_title(t("name", scope: "decidim.proposals.collaborative_drafts")) %>
<% add_decidim_meta_tags(
  description: present(@collaborative_draft).body,
  title: present(@collaborative_draft).title,
  url: collaborative_draft_url(@collaborative_draft.id),
  resource: @collaborative_draft) %>

<%= append_stylesheet_pack_tag "decidim_proposals", media: "all" %>
<%= append_javascript_pack_tag "decidim_proposals" %>

<% content_for :aside do %>
  <%= render partial: "collaborative_draft_aside" %>
<% end %>

<%= render layout: "layouts/decidim/shared/layout_item", locals: { back_path: collaborative_drafts_path } do %>

  <section class="layout-main__section layout-main__heading">
    <%= cell("decidim/announcement", t("info-message", scope: "decidim.proposals.collaborative_drafts.show").html_safe) if current_user.nil? || allowed_to?(:request_access, :collaborative_draft, collaborative_draft: @collaborative_draft) %>

    <h1 class="h2 decorator"><%= present(@collaborative_draft).title(html_escape: true) %></h1>

    <% if component_settings.geocoding_enabled? %>
      <div class="static-map__container">
        <%= render partial: "decidim/shared/static_map", locals: { icon_name: "proposals", geolocalizable: @collaborative_draft } %>
      </div>
    <% end %>

    <% if @collaborative_draft.state %>
      <div class="layout-author has_status">
        <span class="<%= collaborative_drafts_state_class(@collaborative_draft.state) %> label">
          <%= humanize_collaborative_draft_state(@collaborative_draft.state) %>
        </span>
      </div>
    <% end %>

    <div class="layout-author <%= "has_status" if @collaborative_draft.state %>">
      <div class="relative flex items-center justify-center w-full">
        <div class="w-10/12 flex items-center gap-4">
          <%= cell "decidim/coauthorships", @collaborative_draft, context_actions: [] %>
        </div>
        <%= render "decidim/shared/resource_actions", resource: @collaborative_draft do %>
          <%= render "decidim/proposals/collaborative_drafts/collaborative_actions" %>
        <% end %>
      </div>
    </div>
  </section>

  <section class="layout-main__section">
    <div class="editor-content">
      <%= decidim_sanitize_editor present(@collaborative_draft).body(links: true) %>
    </div>
  </section>

  <%= attachments_for @collaborative_draft %>

  <%= cell "decidim/tags", @collaborative_draft %>

  <section class="layout-main__section layout-main__buttons" data-buttons>
    <%= cell "decidim/comments_button", nil %>
    <div class="ml-auto lg:ml-0">
      <%= cell "decidim/share_widget", @collaborative_draft %>
    </div>
  </section>

  <% content_for :item_footer do %>
    <%= comments_for @collaborative_draft %>

    <ul class="metadata__container layout-main__section" data-metadata-footer>
      <%= content_tag :li, resource_reference(@collaborative_draft), class: "metadata__item" %>
      <%= content_tag :li, resource_version(@collaborative_draft, versions_path: collaborative_draft_version_path(@collaborative_draft, @collaborative_draft.versions.count)), class: "metadata__item" %>
    </ul>
  <% end %>

<% end %>
